<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
        //得到排列好的随机数组
        function RandArr(n,min,max,how){
            if(this === window) return new RandArr(n,min,max,how);
            var defaultHow = 'min';
            this.how = how || defaultHow;
            this.n = n;
            this.min = min;
            this.max = max;
            return this.arr();
        }
        RandArr.prototype = {
            constructor:RandArr,
            arr:function(){
                var temp = 0,
                    arr = [],i = 0,
                    that = this;
                function rand(){
                    temp = Math.floor( Math.random() * (that.max - that.min + 1)) + that.min;
                    return arr.indexOf(temp) === -1 ? temp : rand();
                }
                for(; i< this.n; i++){
                    arr.push(rand());
                }
                return arr.sort(function(a,b){return that.how === 'min' ? a - b : b - a; });
            }
        };
        var arr = RandArr(10,1,100);
        console.log(arr);
    </script>
</body>

</html>